<template>
	<view>
		<!-- 搜索栏 -->
		<view class="search">
			<my-search></my-search>
		</view>
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,index) in swiperList" :key='index'>
				<navigator :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id" class="swiper-img">
					<image :src="item.image_src" mode=""></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item,index) in navList" :key='index' @click="goToCate(item)">
				<image :src="item.image_src" mode=""></image>
			</view>
		</view>

		<!-- 楼层区域 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item,index) in floorList" :key='index'>
				<!-- 楼层标题 -->
				<image :src="item.floor_title.image_src" mode="" class="floor-title"></image>
				<!-- 楼层图片区域 -->
				<view class="floor-img-box">
					<!-- 楼层左侧大图 -->
					<view class="floor-left-img-box" @click="goToGoodsList(item.product_list[0])">
						<image :src="item.product_list[0].image_src" mode="widthFix"
							:style="{width: item.product_list[0].image_width+'rpx'}"></image>
					</view>
					<!-- 楼层右侧四张小图 -->
					<view class="floor-right-img-box">
						<view class="right-img-item" v-for="(item2,index2) in item.product_list" :key='index2'
							v-if='index2!==0' @click="goToGoodsList(item2)">
							<image :src="item2.image_src" mode="widthFix" :style="{width: item2.image_width + 'rpx'}">
							</image>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import TabBarBadge from '../../mixins/tabbar-badge.js'
	export default {
		mixins:[TabBarBadge],
		data() {
			return {
				swiperList: [],
				navList: [],
				floorList: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods: {
			// 获取轮播图
			async getSwiperList() {
				const {
					data: {
						message,
						meta
					}
				} = await uni.$http.get('/api/public/v1/home/swiperdata');
				// console.log(res)

				if (meta.status !== 200) {
					return uni.$showMsg()
				}
				this.swiperList = message
			},
			// 获取分类导航数据列表
			async getNavList() {
				const {
					data: {
						message,
						meta
					}
				} = await uni.$http.get('/api/public/v1/home/catitems')
				// console.log(res)
				if (meta.status !== 200) {
					return uni.$showMsg()
				}
				this.navList = message
			},
			// 跳转到分类列表
			goToCate(item) {
				if (item.name == '分类') {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			// 获取楼层数据
			async getFloorList() {
				const {
					data: {
						message,
						meta
					}
				} = await uni.$http.get('/api/public/v1/home/floordata')
				// console.log(message);
				if (meta.status !== 200) {
					return uni.$showMsg()
				}
				
				// 改造数据
				this.floorList=message.map((e,i)=>{
					return {
						product_list:e.product_list.map((v,i2)=>{
							return {
								...v,
								navigator_url:v.navigator_url.split('?')[1]
							}
						}),
						floor_title:e.floor_title
					}
				})
			},
			// 跳转到货物列表
			goToGoodsList(item){
				uni.navigateTo({
					url:'/subpkg/goods_list/goods_list?'+item.navigator_url
					// url:`/subpkg/goods_list/goods_list?${item.navigator_url}`
				})
			}
		}
	}
</script>

<style lang="scss">
	swiper {
		height: 330rpx;

		.swiper-img,
		image {
			width: 100%;
			height: 100%;
		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 15rpx 0;

		image {
			width: 128rpx;
			height: 140rpx;
		}
	}

	.floor-item {
		.floor-title {
			width: 100%;
			height: 60rpx;
			display: flex;
		}

		.floor-img-box {
			display: flex;
			padding-left: 10rpx;

			.floor-right-img-box {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-around;
			}

		}
	}
	.search{
		position: sticky;
		top: 0;
		z-index: 99;
	}
</style>
